<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>创建一个索引 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_creating_an_index.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_creating_an_index.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_creating_an_index.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_creating_an_index.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="getting-started.html">基础入门</a></span>
»
<span class="breadcrumb-link"><a href="index-management.html">索引管理</a></span>
»
<span class="breadcrumb-node">创建一个索引</span>
</div>
<div class="navheader">
<span class="prev">
<a href="index-management.html">« 索引管理</a>
</span>
<span class="next">
<a href="_deleting_an_index.html">删除一个索引 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_creating_an_index"></a>创建一个索引<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/070_Index_Mgmt/05_Create_Delete.asciidoc">edit</a>
</h2>
</div></div></div>
<p>到目前为止, 我们已经通过索引一篇文档创建了一个新的索引  。这个索引采用的是默认的配置，新的字段通过动态映射的方式被添加到类型映射。现在我们需要对这个建立索引的过程做更多的控制：我们想要确保这个索引有数量适中的主分片，并且在我们索引任何数据 <em>之前</em> ，分析器和映射已经被建立好。</p>
<p>为了达到这个目的，我们需要手动创建索引，在请求体里面传入设置或类型映射，如下所示：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">PUT /my_index
{
    "settings": { ... any settings ... },
    "mappings": {
        "type_one": { ... any mappings ... },
        "type_two": { ... any mappings ... },
        ...
    }
}</pre>
</div>
<p>如果你想禁止自动创建索引，你  可以通过在 <code class="literal">config/elasticsearch.yml</code> 的每个节点下添加下面的配置：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">action.auto_create_index: false</pre>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>我们会在之后讨论你怎么用 <a class="xref" href="index-templates.html" title="索引模板">索引模板</a> 来预配置开启自动创建索引。这在索引日志数据的时候尤其有用：你将日志数据索引在一个以日期结尾命名的索引上，子夜时分，一个预配置的新索引将会自动进行创建。</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="index-management.html">« 索引管理</a>
</span>
<span class="next">
<a href="_deleting_an_index.html">删除一个索引 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>